home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
ww_tv.exe
/
TVIEW.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-05
|
20KB
|
804 lines
#pragma warn -stv
/*------------------------------------------------------------*/
/* filename - tview.cpp */
/* */
/* function(s) */
/* TView member functions */
/*------------------------------------------------------------*/
/*------------------------------------------------------------*/
/* */
/* Turbo Vision - Version 1.0 */
/* */
/* */
/* Copyright (c) 1991 by Borland International */
/* All Rights Reserved. */
/* */
/*------------------------------------------------------------*/
// Primatech Modification History:
//
// 11-25-91 JLS Changed change() to have the shift state passed in
// 12-19-91 JLS Added STACKCHECK() (only effects #ifdef DEBUG)
// 05-27-92 JLS In setState(), only tell owner to reset current view
// when it makes sense to do it.
// 05-28-92 JLS In select(), if ofTopSelect and already first, call
// owner->setCurrent() instead of makeFirst()
// 07-05-92 JLS Sync with TV1.03 (BC3.10) -- cosmetic changes
//
#define Uses_TKeys
#define Uses_TView
#define Uses_TCommandSet
#define Uses_TPoint
#define Uses_TGroup
#define Uses_TRect
#define Uses_TEvent
#define Uses_opstream
#define Uses_ipstream
#include <tv.h>
#if !defined( __DOS_H )
#include <Dos.h>
#endif // __DOS_H
#if !defined( __LIMITS_H )
#include <Limits.h>
#endif // __LIMITS_H
#include "StackChk.h"
TPoint shadowSize = {2,1};
uchar shadowAttr = 0x08;
Boolean near TView::showMarkers = False;
uchar near TView::errorAttr = 0xCF;
Boolean near TView::commandSetChanged = False;
extern TView *TheTopView;
static TCommandSet initCommands()
{
TCommandSet temp;
for( int i = 0; i < 256; i++ )
temp.enableCmd( i );
temp.disableCmd( cmZoom );
temp.disableCmd( cmClose );
temp.disableCmd( cmResize );
temp.disableCmd( cmNext );
temp.disableCmd( cmPrev );
return temp;
}
TCommandSet near TView::curCommandSet = initCommands();
TView::TView( const TRect& bounds) :
owner( 0 ), next( 0 ), options( 0 ), state( sfVisible ),
growMode( 0 ), dragMode( dmLimitLoY ), helpCtx( hcNoContext ),
eventMask( evMouseDown | evKeyDown | evCommand )
{
setBounds( bounds);
cursor.x = cursor.y = 0;
}
TView::~TView()
{
}
void TView::blockCursor()
{
setState(sfCursorIns, True);
}
#define grow(i) (( (growMode & gfGrowRel)) ? \
(i = (i * s + ((s - d) >> 1)) / (s - d)) : (i += d))
inline int range( int val, int min, int max )
{
if( val < min )
return min;
else if( val > max )
return max;
else
return val;
}
void TView::calcBounds( TRect& bounds, TPoint delta )
{
bounds = getBounds();
short s = owner->size.x;
short d = delta.x;
if( (growMode & gfGrowLoX) != 0 )
grow(bounds.a.x);
if( (growMode & gfGrowHiX) != 0 )
grow(bounds.b.x);
s = owner->size.y;
d = delta.y;
if( (growMode & gfGrowLoY) != 0 )
grow(bounds.a.y);
if( (growMode & gfGrowHiY) != 0 )
grow(bounds.b.y);
TPoint minLim, maxLim;
sizeLimits( minLim, maxLim );
bounds.b.x = bounds.a.x + range( bounds.b.x-bounds.a.x, minLim.x, maxLim.x );
bounds.b.y = bounds.a.y + range( bounds.b.y-bounds.a.y, minLim.y, maxLim.y );
}
void TView::changeBounds( const TRect& bounds )
{
setBounds(bounds);
drawView();
}
void TView::clearEvent( TEvent& event )
{
STACKCHECK();
event.what = evNothing;
event.message.infoPtr = this;
}
Boolean TView::commandEnabled( ushort command )
{
return Boolean((command > 255) || curCommandSet.has(command));
}
ushort TView::dataSize()
{
return 0;
}
void TView::disableCommands( TCommandSet& commands )
{
commandSetChanged = Boolean( commandSetChanged ||
!(curCommandSet & commands).isEmpty());
curCommandSet.disableCmd(commands);
}
void TView::disableCommand( ushort command )
{
commandSetChanged = Boolean( commandSetChanged ||
curCommandSet.has(command) );
curCommandSet.disableCmd(command);
}
void TView::moveGrow( TPoint p,
TPoint s,
TRect& limits,
TPoint minSize,
TPoint maxSize,
uchar mode
)
{
TRect r;
s.x = min(max(s.x, minSize.x), maxSize.x);
s.y = min(max(s.y, minSize.y), maxSize.y);
p.x = min(max(p.x, limits.a.x - s.x+1), limits.b.x-1);
p.y = min(max(p.y, limits.a.y - s.y+1), limits.b.y-1);
if( (mode & dmLimitLoX) != 0 )
p.x = max(p.x, limits.a.x);
if( (mode & dmLimitLoY) != 0 )
p.y = max(p.y, limits.a.y);
if( (mode & dmLimitHiX) != 0 )
p.x = min(p.x, limits.b.x-s.x);
if( (mode & dmLimitHiY) != 0 )
p.y = min(p.y, limits.b.y-s.y);
r = TRect(p.x, p.y, p.x + s.x, p.y + s.y);
locate(r);
}
void TView::change( uchar mode, TPoint delta, TPoint& p, TPoint& s, uchar shiftState )
{
if( (mode & dmDragMove) != 0 && (shiftState & 3) == 0 )
p += delta;
else if( (mode & dmDragGrow) != 0 && (shiftState & 3) != 0 )
s += delta;
}
void TView::dragView( TEvent& event,
uchar mode,
TRect& limits,
TPoint minSize,
TPoint maxSize
)
{
TRect saveBounds;
TPoint p, s;
setState( sfDragging, True );
if( event.what == evMouseDown )
{
if( (mode & dmDragMove) != 0 )
{
p = origin - event.mouse.where;
do {
event.mouse.where += p;
moveGrow( event.mouse.where,
size,
limits,
minSize,
maxSize,
mode
);
} while( mouseEvent(event,evMouseMove) );
}
else
{
p = size - event.mouse.where;
do {
event.mouse.where += p;
moveGrow( origin,
event.mouse.where,
limits,
minSize,
maxSize,
mode
);
} while( mouseEvent(event,evMouseMove) );
}
}
else
{
static TPoint
goLeft = {-1, 0},
goRight = { 1, 0},
goUp = { 0,-1},
goDown = { 0, 1},
goCtrlLeft = {-8, 0},
goCtrlRight = { 8, 0};
saveBounds = getBounds();
do {
p = origin;
s = size;
keyEvent(event);
switch (event.keyDown.keyCode & 0xFF00)
{
case kbLeft:
change(mode, goLeft, p, s, event.shiftState);
break;
case kbRight:
change(mode, goRight, p, s, event.shiftState);
break;
case kbUp:
change(mode, goUp, p, s, event.shiftState);
break;
case kbDown:
change(mode, goDown, p, s, event.shiftState);
break;
case kbCtrlLeft:
chang